﻿<%@ WebHandler Language="C#" Class="ToUpdateState" %>

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.SessionState;
using BLL;
using DAL;
//编辑状态
public class ToUpdateState : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        Hashtable hs = new Hashtable();
        Tools tool = new Tools();
        PublicSqlService ps = new PublicSqlService();
        string sid = context.Request.Params["Sid"].ToString().Trim();
        hs.Clear();
        hs.Add("Date", tool.StringToTime(context.Request.Params["ndate"].ToString() + " 00:00:01 "));
        hs.Add("StateID", context.Request.Params["state"]);
        hs.Add("RecordDate", DateTime.Now);
        hs.Add("RecorderID", context.Session["uid"].ToString());
        hs.Add("CompanyID", tool.StringToIntDif(context.Request.Params["gs"]));
        hs.Add("CompanyNo", context.Request.Params["zy"]);
        hs.Add("Remark", context.Request.Params["bz"]);
        if (ps.Update(hs, "Tbl_BillStateRec", "BSRID=" + sid))
        {
            string tno = ps.GetWords("Tbl_BillStateRec", "SepNo", "BSRID=" + sid);//查询主单单号
            
            
            
            string sql = "select top 1  a.Stateid,b.Description Description from Tbl_BillStateRec a left join Tbl_BillState b on a.stateid=b.bsid  where     a.SepNo='" + tno + "' order by a.Date desc,a.bsrid desc";
            IPublicSql ip = new IPublicSql();
            IDataReader dr = ip.RunExSql(sql);
            string id = "";
            string name = "";
            if (dr.Read())
            {
                id = dr[0].ToString();
                name = dr[1].ToString();
            }
            dr.Close();
            ip.Close();
            if (id.Trim() != "")
            {
                //只编辑无分单的状态！
                string s = " update Tbl_WayBill set UPEXState='" + name + "',StateId=" + id + ",SepTotal=Total,SepChargedWt=ChargedWt  where   Sep=0 and TrackingNo='" + tno.ToString().Trim() + "'";
                new PublicSqlService().RunSql(s);

            }
            context.Response.Write("ok");
        }
        else
        {
            context.Response.Write("失败");
        }

    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}